home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue65 / clinic / DataSetActionsU.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-11-03  |  1.9 KB  |  82 lines

  1. unit DataSetActionsU;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   ComCtrls, StdCtrls, Db, DBTables, DBActns, ActnList, ImgList;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     ActionList1: TActionList;
  12.     DataSetFirst1: TDataSetFirst;
  13.     DataSetLast1: TDataSetLast;
  14.     DataSetNext1: TDataSetNext;
  15.     DataSetPrior1: TDataSetPrior;
  16.     DataSource1: TDataSource;
  17.     Table1: TTable;
  18.     Label1: TLabel;
  19.     Button1: TButton;
  20.     Button2: TButton;
  21.     procedure Table1AfterScroll(DataSet: TDataSet);
  22.   public
  23.     function ExecuteAction(Action: TBasicAction): Boolean; override;
  24.     function UpdateAction(Action: TBasicAction): Boolean; override;
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. {$R *.DFM}
  33.  
  34. type
  35.   TActionOperation = (aoUpdate, aoExecute);
  36.  
  37. function CheckDataSourceAction(Action: TBasicAction;
  38.   Container: TWinControl;
  39.   Operation: TActionOperation): Boolean;
  40. var
  41.   I: Integer;
  42.   Comp: TComponent;
  43. begin
  44.   for I := 0 to Container.ComponentCount - 1 do
  45.   begin
  46.     Comp := Container.Components[I];
  47.     if (Comp is TDataSource) and Action.HandlesTarget(Comp) then
  48.     begin
  49.       if Operation = aoUpdate then
  50.         Action.UpdateTarget(Comp)
  51.       else
  52.         Action.ExecuteTarget(Comp);
  53.       Result := True;
  54.       Exit
  55.     end;
  56.   end;
  57.   Result := False;
  58. end;
  59.  
  60. function TForm1.ExecuteAction(Action: TBasicAction): Boolean;
  61. begin
  62.   if CheckDataSourceAction(Action, Self, aoExecute) then
  63.     Result := True
  64.   else
  65.     Result := inherited ExecuteAction(Action)
  66. end;
  67.  
  68. procedure TForm1.Table1AfterScroll(DataSet: TDataSet);
  69. begin
  70.   Label1.Caption := Table1['Company']
  71. end;
  72.  
  73. function TForm1.UpdateAction(Action: TBasicAction): Boolean;
  74. begin
  75.   if CheckDataSourceAction(Action, Self, aoUpdate) then
  76.     Result := True
  77.   else
  78.     Result := inherited UpdateAction(Action)
  79. end;
  80.  
  81. end.
  82.